﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ScFramework.Core;
using UnityEngine.UI;

public partial class WorkshopLogic : LogicModuleBase<InputManager, SpriteManager>, ICombineSubUI
{

    ButtonManager buttonManager;
    void ButtonManagerInit()
    {
        buttonManager = new ButtonManager(this);
    }

    void DispatchAlter(CombineUIEvent evt, int id)
    {
        Dispatch(evt,id);
    }

    class ButtonManager
    {
        WorkshopLogic outer;
        public ButtonManager(WorkshopLogic workshopLogic)
        {
            outer = workshopLogic;
            ButtonInit();
        }

        public void ButtonInit()
        {
            for (int i = 0; i < RAW; i++)
            {
                for (int j = 0; j < COL; j++)
                {
                    int newi = new int();
                    int newj = new int();
                    newi = i;
                    newj = j;
                    MyButton btn = Grid.GridList[i][j].singleBlock.GetComponent<MyButton>();        //Button的类型，用MyButton的方法
                   // btn.onClick.AddListener(delegate(){ ItemSelect(newi, newj); });
                    btn.OnDragTrigged += outer.DispatchAlter;
                    btn.OnShowTrigged += outer.DispatchAlter;
                }
            }
        }
        public void ItemSelect(int x, int y)
        {
            int id = 0;
            if(Grid.GridList[x][y].isOccupied == true)
            {
                id = Grid.GridList[x][y].occupyID;
            }
            outer.DispatchAlter(CombineUIEvent.ShowObjectValues, id);
        }
    }
}
